package com.mh.service.impl;

import com.mh.entity.Course;
import com.mh.mapper.CourseMapper;
import com.mh.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper cm;

    @Override
    public List<Course> findAll() {
        return cm.findAll();
    }

    @Override
    public void save(List<Course> courses) {
        //传入的List集合遍历
        courses.forEach(course->{
            //遍历后的元素(对象)都把id设置为null
            course.setCid(null); //不用前端传入的ID,数据库自动生成
            //对象调用Service
            cm.save(course);
        });
    }
}
